home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / javax / swing / JProgressBar.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  25.8 KB  |  825 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)JProgressBar.java    1.70 98/08/28
  3.  *
  4.  * Copyright 1997, 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package javax.swing;
  16.  
  17. import java.awt.Color;
  18. import java.awt.Graphics;
  19.  
  20. import java.io.Serializable;
  21. import java.io.ObjectOutputStream;
  22. import java.io.ObjectInputStream;
  23. import java.io.IOException;
  24.  
  25. import javax.swing.event.*;
  26. import javax.accessibility.*;
  27. import javax.swing.plaf.ProgressBarUI;
  28.  
  29.  
  30. /**
  31.  * A component that displays an integer value within a bounded 
  32.  * interval. A progress bar typically communicates the progress of an 
  33.  * event by displaying its percentage of completion and possibly a textual
  34.  * display of this percentage.
  35.  *
  36.  * <p>
  37.  * <strong>Warning:</strong>
  38.  * Serialized objects of this class will not be compatible with
  39.  * future Swing releases.  The current serialization support is appropriate
  40.  * for short term storage or RMI between applications running the same
  41.  * version of Swing.  A future release of Swing will provide support for
  42.  * long term persistence.
  43.  *
  44.  * @beaninfo
  45.  *      attribute: isContainer false
  46.  *    description: A component that displays an integer value.
  47.  *
  48.  * @version 1.70 08/28/98
  49.  * @author Michael C. Albers
  50.  */
  51. public class JProgressBar extends JComponent implements SwingConstants, Accessible
  52. {
  53.     /**
  54.      * @see #getUIClassID
  55.      */
  56.     private static final String uiClassID = "ProgressBarUI";
  57.  
  58.     /**
  59.      * The orientation to display the progress bar.
  60.      * The default is HORIZONTAL.
  61.      */
  62.     protected int orientation;
  63.     /**
  64.      * Whether to display the border around the progress bar.
  65.      * The default is true.
  66.      */
  67.     protected boolean paintBorder;
  68.     /**
  69.      * The data structure that holds the various values for the progress bar.
  70.      */
  71.     protected BoundedRangeModel model;
  72.     /**
  73.      * A optional String that can be displayed on the progress bar.
  74.      * The default is null. Setting this to a non-null value does not
  75.      * imply that the String will be displayed.
  76.      */
  77.     protected String progressString;
  78.     /**
  79.      * Whether to textually display a String on the progress bar.
  80.      * The default is false. Setting this to true will cause a textual
  81.      * display of the progress to de rendered on the progress bar. If
  82.      * the progressString is null, the percentage done to be displayed 
  83.      * on the progress bar. If the progressString is non-null, it is
  84.      * rendered on the progress bar.
  85.      */
  86.     protected boolean paintString;
  87.     /**
  88.      * The default minimum for a progress bar is 0.
  89.      */
  90.     static final private int defaultMinimum = 0;
  91.     /**
  92.      * The default maximum for a progress bar is 100.
  93.      */
  94.     static final private int defaultMaximum = 100;
  95.     /**
  96.      * The default orientation for a progress bar is HORIZONTAL.
  97.      */
  98.     static final private int defaultOrientation = HORIZONTAL;
  99.  
  100.     /**
  101.      * Only one ChangeEvent is needed per instance since the
  102.      * event's only interesting property is the immutable source, which
  103.      * is the progress bar.
  104.      */
  105.     protected transient ChangeEvent changeEvent = null;
  106.     protected ChangeListener changeListener = null;
  107.  
  108.  
  109.    /**
  110.      * Creates a horizontal progress bar.
  111.      * The default orientation for progress bars is
  112.      * <code>JProgressBar.HORIZONTAL</code>.
  113.      * By default, the String is set to <code>null</code> and the 
  114.      * StringPainted is not painted.
  115.      * The border is painted by default.
  116.      * Uses the defaultMinimum (0) and defaultMaximum (100).
  117.      * Uses the defaultMinimum for the initial value of the progress bar.
  118.      */
  119.     public JProgressBar()
  120.     {
  121.     this(defaultOrientation);
  122.     }
  123.  
  124.    /**
  125.      * Creates a progress bar with the specified orientation, which can be 
  126.      * either <code>JProgressBar.VERTICAL</code> or 
  127.      * <code>JProgressBar.HORIZONTAL</code>.
  128.      * By default, the String is set to <code>null</code> and the 
  129.      * StringPainted is not painted.
  130.      * The border is painted by default.
  131.      * Uses the defaultMinimum (0) and defaultMaximum (100).
  132.      * Uses the defaultMinimum for the initial value of the progress bar.
  133.      */
  134.     public JProgressBar(int orient)
  135.     {
  136.     this(orient, defaultMinimum, defaultMaximum);
  137.     }
  138.  
  139.  
  140.     /**
  141.      * Creates a horizontal progress bar, which is the default.
  142.      * By default, the String is set to <code>null</code> and the 
  143.      * StringPainted is not painted.
  144.      * The border is painted by default.
  145.      * Uses the specified minimum and maximum.
  146.      * Uses the specified minimum for the initial value of the progress bar.
  147.      */
  148.     public JProgressBar(int min, int max)
  149.     {
  150.     this(defaultOrientation, min, max);
  151.     }
  152.  
  153.  
  154.     /**
  155.      * Creates a progress bar using the specified orientation,
  156.      * minimum, and maximum.
  157.      * By default, the String is set to <code>null</code> and the 
  158.      * StringPainted is not painted.
  159.      * The border is painted by default.
  160.      * Sets the inital value of the progress bar to the specified minimum.
  161.      * The BoundedRangeModel that sits underneath the progress bar
  162.      * handles any issues that may arrise from improperly setting the 
  163.      * minimum, value, and maximum on the progress bar.
  164.      *
  165.      * @see BoundedRangeModel
  166.      * @see #setOrientation
  167.      * @see #setBorderPainted
  168.      * @see #setStringPainted
  169.      * @see #setString
  170.      */
  171.     public JProgressBar(int orient, int min, int max)
  172.     {
  173.     // Creating the model this way is a bit simplistic, but
  174.     //  I believe that it is the the most common usage of this
  175.     //  component - it's what people will expect.
  176.         setModel(new DefaultBoundedRangeModel(min, 0, min, max));
  177.         updateUI();
  178.  
  179.         setOrientation(orient);      // documented with set/getOrientation()
  180.         setBorderPainted(true);      // documented with is/setBorderPainted()
  181.     setStringPainted(false);     // see setStringPainted
  182.     setString(null);             // see getString
  183.     }
  184.  
  185.  
  186.     /**
  187.      * Creates a horizontal progress bar, the default orientation.
  188.      * By default, the String is set to <code>null</code> and the 
  189.      * StringPainted is not painted.
  190.      * The border is painted by default.
  191.      * Uses the specified BoundedRangeModel
  192.      * which holds the minimum, value, and maximum.
  193.      *
  194.      * @see BoundedRangeModel
  195.      * @see #setOrientation
  196.      * @see #setBorderPainted
  197.      * @see #setStringPainted
  198.      * @see #setString
  199.      */
  200.     public JProgressBar(BoundedRangeModel newModel)
  201.     {
  202.         setModel(newModel);
  203.         updateUI();
  204.  
  205.         setOrientation(defaultOrientation);  // see setOrientation()
  206.         setBorderPainted(true);              // see setBorderPainted()
  207.     setStringPainted(false);             // see setStringPainted
  208.     setString(null);                     // see getString
  209.     }
  210.  
  211.  
  212.     /**
  213.      * Returns <code>JProgressBar.VERTICAL</code> or 
  214.      * <code>JProgressBar.HORIZONTAL</code>, depending on the orientation
  215.      * of the progress bar. The default orientation is 
  216.      * <code>HORIZONTAL</code>.
  217.      *
  218.      * @return HORIZONTAL or VERTICAL
  219.      * @see #setOrientation
  220.      */
  221.     public int getOrientation() {
  222.         return orientation;
  223.     }
  224.  
  225.  
  226.    /**
  227.      * Sets the progress bar's orientation to <I>newOrientation</I>, which
  228.      * must be <code>JProgressBar.VERTICAL</code> or 
  229.      * <code>JProgressBar.HORIZONTAL</code>. The default orientation 
  230.      * is <code>HORIZONTAL</code>.
  231.      *
  232.      * @param  newOrientation  HORIZONTAL or VERTICAL
  233.      * @exception      IllegalArgumentException    if <I>newOrientation</I>
  234.      *                                              is an illegal value
  235.      * @see #getOrientation
  236.      *
  237.      * @beaninfo
  238.      *    preferred: true
  239.      *        bound: true
  240.      *    attribute: visualUpdate true
  241.      *  description: Set the progress bar's orientation.
  242.      */
  243.     public void setOrientation(int newOrientation) {
  244.         if (orientation != newOrientation) {
  245.             switch (newOrientation) {
  246.             case VERTICAL:
  247.             case HORIZONTAL:
  248.                 int oldOrientation = orientation;
  249.                 orientation = newOrientation;
  250.                 firePropertyChange("orientation", oldOrientation, newOrientation);
  251.                 if (accessibleContext != null) {
  252.                     accessibleContext.firePropertyChange(
  253.                 AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
  254.                             ((oldOrientation == VERTICAL) 
  255.                  ? AccessibleState.VERTICAL 
  256.                  : AccessibleState.HORIZONTAL),
  257.                             ((orientation == VERTICAL) 
  258.                  ? AccessibleState.VERTICAL 
  259.                  : AccessibleState.HORIZONTAL));
  260.             }
  261.                 break;
  262.             default:
  263.                 throw new IllegalArgumentException(newOrientation +
  264.                                              " is not a legal orientation");
  265.             }
  266.             revalidate();
  267.         }
  268.     }
  269.  
  270.  
  271.     /**
  272.      * Returns true if the progress bar will render a string onto
  273.      * the representation of the progress bar. Returns false if it
  274.      * will not do this rendering. The default is false - the progress
  275.      * bar does not draw the string by default.
  276.      *
  277.      * @return whether the progress bar renders a string
  278.      * @see    #setStringPainted
  279.      * @see    #setString
  280.      */
  281.     public boolean isStringPainted() {
  282.         return paintString;
  283.     }
  284.  
  285.  
  286.     /**
  287.      * Sets whether the progress bar will render a string.
  288.      *
  289.      * @param   b       true if the progress bar will render a string.
  290.      * @see     #isStringPainted
  291.      * @beaninfo
  292.      *        bound: true
  293.      *    attribute: visualUpdate true
  294.      *  description: Whether the progress bar will render a string.
  295.      */
  296.     public void setStringPainted(boolean b) {
  297.         boolean oldValue = paintString;
  298.         paintString = b;
  299.         firePropertyChange("stringPainted", oldValue, paintString);
  300.         if (paintString != oldValue) {
  301.         revalidate();
  302.             repaint();
  303.         }
  304.     }
  305.  
  306.  
  307.     /**
  308.      * Returns the current value of the Progress String.
  309.      * If you are providing a custom Progress String via this method,
  310.      * you will want to ensure that you call setString() before
  311.      * you call getString();
  312.      *
  313.      * @return the value of the percent string
  314.      * @see    #setString
  315.      */
  316.     public String getString(){
  317.     if (progressString != null) {
  318.         return progressString;
  319.     } else {
  320.         int pc = (int)Math.round(100 * getPercentComplete());
  321.         return new String(pc + "%");
  322.     }
  323.     }
  324.  
  325.     /**
  326.      * Sets the value of the Progress String. By default,
  327.      * this String is set to <code>null</code>.
  328.      * If you are providing a custom Progress String via this method,
  329.      * you will want to ensure that you call setString() before
  330.      * you call getString().
  331.      * If you have provided a custom String and want to revert to 
  332.      * the built-in behavior, set the String back to <code>null</code>.
  333.      *
  334.      * @param  s       the value of the percent string
  335.      * @see    #getString
  336.      * @beaninfo
  337.      *        bound: true
  338.      *    attribute: visualUpdate true
  339.      *  description: Whether the progress bar will render a percent string
  340.      */
  341.     public void setString(String s){
  342.         String oldValue = progressString;
  343.     progressString = s;
  344.         firePropertyChange("string", oldValue, progressString);
  345.         if (progressString == null || oldValue == null || !progressString.equals(oldValue)) {
  346.         repaint();
  347.         }
  348.     }
  349.  
  350.     /**
  351.      * Returns the percentage/percent complete for the progress bar.
  352.      * Note that, as a double, this number is between 0.00 and 1.00.
  353.      *
  354.      * @return the percent complete for this progress bar. 
  355.      */
  356.     public double getPercentComplete() {
  357.     long span = model.getMaximum() - model.getMinimum();
  358.     double currentValue = model.getValue();
  359.     double pc = (currentValue - model.getMinimum()) / span;
  360.     return pc;
  361.     }
  362.  
  363.     /**
  364.      * Returns true if the progress bar has a border or false if it does not.
  365.      * By default, this is true - the progress bar paints it's border.
  366.      *
  367.      * @return whether the progress bar paints its border
  368.      * @see    #setBorderPainted
  369.      * @beaninfo
  370.      *  description: Does the progress bar paint its border
  371.      */
  372.     public boolean isBorderPainted() {
  373.         return paintBorder;
  374.     }
  375.  
  376.     /**
  377.      * Sets whether the progress bar should paint its border.
  378.      * By default, this is true - paint the border.
  379.      *
  380.      * @param   b       true if the progress bar paints its border
  381.      * @see     #isBorderPainted
  382.      * @beaninfo
  383.      *        bound: true
  384.      *    attribute: visualUpdate true
  385.      *  description: Whether the progress bar should paint its border.
  386.      */
  387.     public void setBorderPainted(boolean b) {
  388.         boolean oldValue = paintBorder;
  389.         paintBorder = b;
  390.         firePropertyChange("borderPainted", oldValue, paintBorder);
  391.         if (paintBorder != oldValue) {
  392.             repaint();
  393.         }
  394.     }
  395.  
  396.     /**
  397.      * Paint the progress bar's border if BorderPainted property is true.
  398.      * 
  399.      * @param g  the Graphics context within which to paint the border
  400.      * @see #paint
  401.      * @see #setBorder
  402.      * @see #isBorderPainted
  403.      * @see #setBorderPainted
  404.      */
  405.     protected void paintBorder(Graphics g) {    
  406.         if (isBorderPainted()) {
  407.             super.paintBorder(g);
  408.         }
  409.     }
  410.  
  411.  
  412.     /**
  413.      * Returns the L&F object that renders this component.
  414.      *
  415.      * @return the ProgressBarUI object that renders this component
  416.      */
  417.     public ProgressBarUI getUI() {
  418.         return (ProgressBarUI)ui;
  419.     }
  420.  
  421.     /**
  422.      * Sets the L&F object that renders this component.
  423.      *
  424.      * @param ui  the ProgressBarUI L&F object
  425.      * @see UIDefaults#getUI
  426.      * @beaninfo
  427.      *       expert: true
  428.      *    attribute: visualUpdate true
  429.      *  description: The ProgressBarUI implementation that defines the progress bar's look and feel.
  430.      */
  431.     public void setUI(ProgressBarUI ui) {
  432.         super.setUI(ui);
  433.     }
  434.  
  435.  
  436.     /**
  437.      * Notification from the UIFactory that the L&F has changed. 
  438.      * Called to replace the UI with the latest version from the 
  439.      * UIFactory.
  440.      *
  441.      * @see JComponent#updateUI
  442.      */
  443.     public void updateUI() {
  444.         setUI((ProgressBarUI)UIManager.getUI(this));
  445.     }
  446.  
  447.  
  448.     /**
  449.      * Returns the name of the L&F class that renders this component.
  450.      *
  451.      * @return "ProgressBarUI"
  452.      * @see JComponent#getUIClassID
  453.      * @see UIDefaults#getUI
  454.      * @beaninfo
  455.      *        expert: true
  456.      *   description: A string that specifies the name of the L&F class.
  457.      */
  458.     public String getUIClassID() {
  459.         return uiClassID;
  460.     }
  461.  
  462.  
  463.     /* We pass each Change event to the listeners with the
  464.      * the progress bar as the event source.
  465.      * <p>
  466.      * <strong>Warning:</strong>
  467.      * Serialized objects of this class will not be compatible with
  468.      * future Swing releases.  The current serialization support is appropriate
  469.      * for short term storage or RMI between applications running the same
  470.      * version of Swing.  A future release of Swing will provide support for
  471.      * long term persistence.
  472.      */
  473.     private class ModelListener implements ChangeListener, Serializable {
  474.         public void stateChanged(ChangeEvent e) {
  475.             fireStateChanged();
  476.         }
  477.     }
  478.  
  479.     /* Subclasses that want to handle ChangeEvents differently
  480.      * can override this to return a subclass of ModelListener or
  481.      * another ChangeListener implementation.
  482.      */
  483.     protected ChangeListener createChangeListener() {
  484.         return new ModelListener();
  485.     }
  486.  
  487.     /**
  488.      * Adds a ChangeListener to the button.
  489.      *
  490.      * @param l the ChangeListener to add
  491.      */
  492.     public void addChangeListener(ChangeListener l) {
  493.         listenerList.add(ChangeListener.class, l);
  494.     }
  495.     
  496.     /**
  497.      * Removes a ChangeListener from the button.
  498.      *
  499.      * @param l the ChangeListener to remove
  500.      */
  501.     public void removeChangeListener(ChangeListener l) {
  502.         listenerList.remove(ChangeListener.class, l);
  503.     }
  504.         
  505.     /**
  506.      * Notify all listeners that have registered interest for
  507.      * notification on this event type.  The event instance 
  508.      * is lazily created using the parameters passed into 
  509.      * the fire method.
  510.      * @see EventListenerList
  511.      */
  512.     protected void fireStateChanged() {
  513.         // Guaranteed to return a non-null array
  514.         Object[] listeners = listenerList.getListenerList();
  515.         // Process the listeners last to first, notifying
  516.         // those that are interested in this event
  517.         for (int i = listeners.length-2; i>=0; i-=2) {
  518.             if (listeners[i]==ChangeListener.class) {
  519.                 // Lazily create the event:
  520.                 if (changeEvent == null)
  521.                     changeEvent = new ChangeEvent(this);
  522.                 ((ChangeListener)listeners[i+1]).stateChanged(changeEvent);
  523.             }          
  524.         }
  525.     } 
  526.       
  527.     /**
  528.      * Returns the data model used by the JProgressBar.
  529.      *
  530.      * @return the BoundedRangeModel currently in use
  531.      * @see    BoundedRangeModel
  532.      */
  533.     public BoundedRangeModel getModel() {
  534.         return model;
  535.     }
  536.  
  537.     /**
  538.      * Sets the data model used by the JProgressBar.
  539.      *
  540.      * @param  newModel the BoundedRangeModel to use
  541.      * @see    BoundedRangeModel
  542.      * @beaninfo
  543.      *    expert: true
  544.      * description: The data model used by the JProgressBar.
  545.      */
  546.     public void setModel(BoundedRangeModel newModel) {
  547.         // PENDING(???) setting the same model to multiple bars is broken; listeners
  548.         BoundedRangeModel oldModel = getModel();
  549.  
  550.         if (newModel != oldModel) {
  551.             if (oldModel != null) {
  552.                 oldModel.removeChangeListener(changeListener);
  553.                 changeListener = null;
  554.             }
  555.  
  556.             model = newModel;
  557.  
  558.             if (newModel != null) {
  559.                 changeListener = createChangeListener();
  560.                 newModel.addChangeListener(changeListener);
  561.             }
  562.  
  563.         if (accessibleContext != null) {
  564.                 accessibleContext.firePropertyChange(
  565.                 AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
  566.                         (oldModel== null 
  567.              ? null : new Integer(oldModel.getValue())),
  568.                         (newModel== null 
  569.              ? null : new Integer(newModel.getValue())));
  570.         }
  571.  
  572.             model.setExtent(0);
  573.             repaint();
  574.         }
  575.     }
  576.  
  577.  
  578.     /* All of the model methods are implemented by delegation. */
  579.  
  580.     /**
  581.      * Returns the model's current value. The value is always between the 
  582.      * model's minimum and maximum values, inclusive. By default, the value
  583.      * equals the minimum.
  584.      *
  585.      * @return  the value
  586.      * @see     #setValue
  587.      * @see     BoundedRangeModel
  588.      */
  589.     public int getValue() { return getModel().getValue(); }
  590.  
  591.     /**
  592.      * Returns the model's minimum value.
  593.      * By default, this is <code>0</code>.
  594.      *
  595.      * @return  an int -- the model's minimum
  596.      * @see     #setMinimum
  597.      * @see     BoundedRangeModel
  598.      */
  599.     public int getMinimum() { return getModel().getMinimum(); }
  600.  
  601.     /**
  602.      * Returns the model's maximum value.
  603.      * By default, this is <code>100</code>.
  604.      *
  605.      * @return  an int -- the model's maximum
  606.      * @see     #setMaximum
  607.      * @see     BoundedRangeModel
  608.      */
  609.     public int getMaximum() { return getModel().getMaximum(); }
  610.  
  611.     /**
  612.      * Sets the model's current value to <I>x</I>.
  613.      * The underlying BoundedRangeModel will handle any mathematical
  614.      * issues arrising from assigning faulty values.
  615.      *
  616.      * @param   x       the new value
  617.      * @see     #getValue
  618.      * @see     BoundedRangeModel#setValue
  619.      * @beaninfo
  620.      *    preferred: true
  621.      *  description: The model's current value.
  622.      */
  623.     public void setValue(int n) { 
  624.         BoundedRangeModel brm = getModel();
  625.     int oldValue = brm.getValue();
  626.     brm.setValue(n);
  627.  
  628.     if (accessibleContext != null) {
  629.             accessibleContext.firePropertyChange(
  630.             AccessibleContext.ACCESSIBLE_VALUE_PROPERTY,
  631.                     new Integer(oldValue),
  632.                     new Integer(brm.getValue()));
  633.     }
  634.     }
  635.  
  636.     /**
  637.      * Sets the model's minimum to <I>x</I>.
  638.      * The underlying BoundedRangeModel will handle any mathematical
  639.      * issues arrising from assigning faulty values.
  640.      * <p>
  641.      * Notifies any listeners if the data changes.
  642.      *
  643.      * @param  x       the new minimum
  644.      * @see    #getMinimum
  645.      * @see    #addChangeListener
  646.      * @see    BoundedRangeModel
  647.      * @beaninfo
  648.      *  preferred: true
  649.      * description: The model's minimum value.
  650.      */
  651.     public void setMinimum(int n) { getModel().setMinimum(n); }
  652.  
  653.     /**
  654.      * Sets the model's maximum to <I>x</I>.
  655.      * The underlying BoundedRangeModel will handle any mathematical
  656.      * issues arrising from assigning faulty values.
  657.      * <p>
  658.      * Notifies any listeners if the data changes.
  659.      *
  660.      * @param  x       the new maximum
  661.      * @see    #getMaximum
  662.      * @see    #addChangeListener
  663.      * @see    BoundedRangeModel
  664.      * @beaninfo
  665.      *    preferred: true
  666.      *  description: The model's maximum value.
  667.      */
  668.     public void setMaximum(int n) { getModel().setMaximum(n); }
  669.  
  670.  
  671.     /** 
  672.      * See readObject() and writeObject() in JComponent for more 
  673.      * information about serialization in Swing.
  674.      */
  675.     private void writeObject(ObjectOutputStream s) throws IOException {
  676.         s.defaultWriteObject();
  677.     if ((ui != null) && (getUIClassID().equals(uiClassID))) {
  678.         ui.installUI(this);
  679.     }
  680.     }
  681.  
  682.  
  683.     /**
  684.      * Returns a string representation of this JProgressBar. This method 
  685.      * is intended to be used only for debugging purposes, and the 
  686.      * content and format of the returned string may vary between      
  687.      * implementations. The returned string may be empty but may not 
  688.      * be <code>null</code>.
  689.      * <P>
  690.      * Overriding paramString() to provide information about the
  691.      * specific new aspects of the JFC components.
  692.      * 
  693.      * @return  a string representation of this JProgressBar.
  694.      */
  695.     protected String paramString() {
  696.     String orientationString = (orientation == HORIZONTAL ?
  697.                     "HORIZONTAL" : "VERTICAL");
  698.     String paintBorderString = (paintBorder ?
  699.                     "true" : "false");
  700.     String progressStringString = (progressString != null ?
  701.                        progressString : "");
  702.     String paintStringString = (paintString ?
  703.                     "true" : "false");
  704.  
  705.     return super.paramString() +
  706.     ",orientation=" + orientationString +
  707.     ",paintBorder=" + paintBorderString +
  708.     ",paintString=" + paintStringString +
  709.     ",progressString=" + progressStringString;
  710.     }
  711.  
  712. /////////////////
  713. // Accessibility support
  714. ////////////////
  715.  
  716.     /**
  717.      * Get the AccessibleContext associated with this JComponent
  718.      *
  719.      * @return the AccessibleContext of this JComponent
  720.      * @beaninfo
  721.      *       expert: true
  722.      *  description: The AccessibleContext associated with this ProgressBar.
  723.      */
  724.     public AccessibleContext getAccessibleContext() {
  725.         if (accessibleContext == null) {
  726.             accessibleContext = new AccessibleJProgressBar();
  727.         }
  728.         return accessibleContext;
  729.     }
  730.  
  731.     /**
  732.      * The class used to obtain the accessible role for this object.
  733.      * <p>
  734.      * <strong>Warning:</strong>
  735.      * Serialized objects of this class will not be compatible with
  736.      * future Swing releases.  The current serialization support is appropriate
  737.      * for short term storage or RMI between applications running the same
  738.      * version of Swing.  A future release of Swing will provide support for
  739.      * long term persistence.
  740.      */
  741.     protected class AccessibleJProgressBar extends AccessibleJComponent
  742.         implements AccessibleValue {
  743.  
  744.         /**
  745.          * Get the state set of this object.
  746.          *
  747.          * @return an instance of AccessibleState containing the current state 
  748.          * of the object
  749.          * @see AccessibleState
  750.          */
  751.         public AccessibleStateSet getAccessibleStateSet() {
  752.             AccessibleStateSet states = super.getAccessibleStateSet();
  753.             if (getModel().getValueIsAdjusting()) {
  754.                 states.add(AccessibleState.BUSY);
  755.             }
  756.             if (getOrientation() == VERTICAL) {
  757.                 states.add(AccessibleState.VERTICAL);
  758.             } else {
  759.                 states.add(AccessibleState.HORIZONTAL);
  760.             }
  761.             return states;
  762.         }
  763.  
  764.         /**
  765.          * Get the role of this object.
  766.          *
  767.          * @return an instance of AccessibleRole describing the role of the 
  768.          * object
  769.          */
  770.         public AccessibleRole getAccessibleRole() {
  771.             return AccessibleRole.PROGRESS_BAR;
  772.         }
  773.  
  774.         /**
  775.          * Get the AccessibleValue associated with this object if one
  776.          * exists.  Otherwise return null.
  777.          */
  778.         public AccessibleValue getAccessibleValue() {
  779.             return this;
  780.         }
  781.  
  782.         /**
  783.          * Get the accessible value of this object.
  784.          *
  785.          * @return The current value of this object.
  786.          */
  787.         public Number getCurrentAccessibleValue() {
  788.             return new Integer(getValue());
  789.         }
  790.  
  791.         /**
  792.          * Set the value of this object as a Number.
  793.          *
  794.          * @return True if the value was set.
  795.          */
  796.         public boolean setCurrentAccessibleValue(Number n) {
  797.             if (n instanceof Integer) {
  798.                 setValue(n.intValue());
  799.                 return true;
  800.             } else {
  801.                 return false;
  802.             }
  803.         }
  804.  
  805.         /**
  806.          * Get the minimum accessible value of this object.
  807.          *
  808.          * @return The minimum value of this object.
  809.          */
  810.         public Number getMinimumAccessibleValue() {
  811.             return new Integer(getMinimum());
  812.         }
  813.  
  814.         /**
  815.          * Get the maximum accessible value of this object.
  816.          *
  817.          * @return The maximum value of this object.
  818.          */
  819.         public Number getMaximumAccessibleValue() {
  820.             return new Integer(getMaximum());
  821.         }
  822.  
  823.     } // AccessibleJProgressBar
  824. }
  825.